package org.jiuling.tencentcloud.cos.config;


import org.jiuling.basics.validation.ArrayVerify;
import org.jiuling.basics.validation.IntegerVerify;

/**
 * 腾讯CosSts配置
 * @author 紫灵
 * @date 2024年02月23日 21时32分49秒
 */
public class TencentCosStsConfig {

    /** 有效时长 */
    private int durationSeconds;
    /** 允许前缀 */
    private String[] allowPrefixes;
    /** 允许的行为 */
    private String[] allowActions;

    public int getDurationSeconds() {
        return durationSeconds;
    }

    public void setDurationSeconds(int durationSeconds) {
        this.durationSeconds = durationSeconds;
    }

    public String[] getAllowPrefixes() {
        return allowPrefixes;
    }

    public void setAllowPrefixes(String[] allowPrefixes) {
        this.allowPrefixes = allowPrefixes;
    }

    public String[] getAllowActions() {
        return allowActions;
    }

    public void setAllowActions(String[] allowActions) {
        this.allowActions = allowActions;
    }

    /**
     * 建造者
     * @return 建造者
     */
    public static Builder builder(){
        return new Builder();
    }

    /**
     * 建造者
     */
    public static class Builder{
        private final TencentCosStsConfig tencentCosStsConfig;

        public Builder() {
            this.tencentCosStsConfig = new TencentCosStsConfig();
        }

        public Builder addDurationSeconds(int durationSeconds) {
            tencentCosStsConfig.durationSeconds = durationSeconds;
            return this;
        }

        public Builder addAllowPrefixes(String[] allowPrefixes) {
            tencentCosStsConfig.allowPrefixes = allowPrefixes;
            return this;
        }

        public Builder addAllowActions(String[] allowActions) {
            tencentCosStsConfig.allowActions = allowActions;
            return this;
        }

        public TencentCosStsConfig build(){
            if(IntegerVerify.isBlank(tencentCosStsConfig.durationSeconds)){
                tencentCosStsConfig.durationSeconds = 1800;
            }
            if(ArrayVerify.isEmpty(tencentCosStsConfig.allowActions)){
                tencentCosStsConfig.allowActions = new String[]{"*"};
            }
            if(ArrayVerify.isEmpty(tencentCosStsConfig.allowPrefixes)){
                tencentCosStsConfig.allowPrefixes = new String[]{"*"};
            }
            return tencentCosStsConfig;
        }


    }
}
